package com.example.t1.view;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.t1.R;

public class LoginDialogView extends AlertDialog.Builder implements OnClickListener{

	private View view;
	public LoginDialogView(Context context, Activity activity) {
		super(context);
		initDialog(activity);
	}

    private void initDialog(Activity activity){
	    LayoutInflater inflater = activity.getLayoutInflater();
	    view = inflater.inflate(R.layout.login_view, (ViewGroup) activity.findViewById(R.id.loginView));
	    setTitle(R.string.login_dialogLabel);
	    setView(view);
	    Button loginButton = (Button) view.findViewById(R.id.login_loginButton);
	    loginButton.setOnClickListener(this);
    }
    
    private void processLoginButtonClicked(View view) {
    	EditText username = (EditText)view.findViewById(R.id.login_usernameField);
		EditText password = (EditText)view.findViewById(R.id.login_passwordField);
    	Toast.makeText(view.getContext(), username.getText(), Toast.LENGTH_SHORT).show();
    	Toast.makeText(view.getContext(), password.getText(), Toast.LENGTH_LONG).show();
    }

	public void onClick(View v) {
		processLoginButtonClicked(this.view);
	}
}
